const apiList = {
  getCabinet: "/cabinet/getCabinet",
  getGridByGzid: "/grid/getGridByGzid",
}
let host = location.origin
host = "http://127.0.0.1:8360"

axios.defaults.baseURL = host

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  let data = response.data
  if (data.errno !== 0) {
    return Promise.reject(new Error(data.message));
  }
  return data.data;
}, function (error) {
  let response = error.response
  if (response) {
    if (response.data) {
      return Promise.reject(new Error(response.data.message));
    }
  }
  return Promise.reject(error);
});

window.$api = new Proxy({}, {
  get(target, p, receiver) {
    return (data) => {
      return axios.post(apiList[p], data)
    }
  }
})
